package com.adun.scheduler.local.job;


import com.adun.scheduler.AbstractSchedulerJob;
import com.adun.scheduler.local.properties.LocalTaskProperties;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

/**
 * @author ADUN
 * @date 2025/8/16 16:10
 */
@Slf4j
@Component
@RequiredArgsConstructor(onConstructor_ = @__(@Autowired))
@EnableConfigurationProperties(LocalTaskProperties.class)
public class SchedulerPrintJob extends AbstractSchedulerJob<SchedulerPrintJob> {

    private final LocalTaskProperties localTaskProperties;

    @Override
    public void initJobParams() {
        // 必须英文格式, 建议bean名称，可空，默认取beanName
        setJobName("schedulerPrintJob");
        setJobDescription("打印定时任务");
        setJobCron(localTaskProperties.getCron());
        // 分配线程池核心线程数
        setScheduledThreadPoolCoreSize(2);
        // 线程前缀
        setScheduledThreadPrefix("loc-t-");
    }

    @Override
    public void execute() {
        try {
            LocalDateTime now = LocalDateTime.now();
            DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
            String format = dateTimeFormatter.format(now);
            System.out.println(format + ":打印1111111111111");
        } catch (Exception e) {
            log.error("【定时任务执行失败】:", e);
        }
    }
}
